﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace catbm_winform
{
    public partial class Login : Form
    {
        private Label usernameLabel;
        private TextBox usernameTextBox;
        private Label passwordLabel;
        private TextBox passwordTextBox;
        private Button loginButton;

        public Login()
        {
            InitializeComponent();

            // 以下是构造函数里面添加布局的代码，一般是在设计器里面完成的(designer.cs)

            // this.usernameLabel = new Label() { Text = "Username:", Location = new Point(10, 10) };
            // this.usernameTextBox = new TextBox() { Location = new Point(10, 30) };

            // this.passwordLabel = new Label() { Text = "Password:", Location = new Point(10, 60) };
            // this.passwordTextBox = new TextBox() { Location = new Point(10, 80), PasswordChar = '*' };

            // this.loginButton = new Button() { Text = "Login", Location = new Point(10, 110) };
            // this.loginButton.Click += LoginButton_Click;

            // this.Controls.Add(this.usernameLabel);
            // this.Controls.Add(this.usernameTextBox);
            // this.Controls.Add(this.passwordLabel);
            // this.Controls.Add(this.passwordTextBox);
            // this.Controls.Add(this.loginButton);
        }

        private void LoginButton_Click(object sender, EventArgs e)
        {
            // 在这里添加登录逻辑
            //          DatabaseHelper db = new DatabaseHelper();

            // if (db.ValidateUser(usernameTextBox.Text, passwordTextBox.Text))
            if (usernameTextBox.Text == "68521" && passwordTextBox.Text == "ichangan@ps_6")
            {
                // 创建Form1的新实例并显示
                Form1 form1 = new Form1();
                form1.Show();

                // 可选：隐藏当前窗口
                this.Hide();
            }
            else
            {
                MessageBox.Show($"Username: {usernameTextBox.Text}\nPassword: {passwordTextBox.Text}");
            }

        }

        private void Login_Load(object sender, EventArgs e)
        {
            Console.WriteLine("当前不是控制台应用，所以不会输出到控制台");
            System.Diagnostics.Debug.WriteLine("Login_Load" + this.ToString()); // 这个只能接受一个参数 这里只会输出类名
            //             foreach (var prop in this.GetType().GetProperties())
            // {
            //     System.Diagnostics.Debug.WriteLine($"Name: {prop.Name}, Value: {prop.GetValue(this)}");
            // }
            this.AcceptButton = loginButton; // 设置默认按钮 键盘按下回车时会触发这个按钮的Click事件,可在构造函数里面设置
        }

        private void usernameTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void passwordTextBox_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
